package com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.assembler;

import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchConfiguratReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.vo.dispatch.DispatchConfiguratRespVO;
import com.jwds.digital.bios.business.core.infrastructure.entity.dispatch.DispatchConfigurat;
import java.util.Objects;

/**
 * DispatchConfigurat DTO与Entity之间的相互转换
 *
 * @author 林柏云
 * @date 2024-10-24
 */
public class DispatchConfiguratAssembler {

  /**
  * 将传输对象转换为实体对象
  *
  * @param dto 传输对象
  * @return 实体对象
  */
  public static DispatchConfigurat dto2entity(DispatchConfiguratReqDTO dto)  {
    if (dto == null) {
      return null;
    }
    DispatchConfigurat entity = new DispatchConfigurat();
    entity.setSortOrder(Integer.valueOf(dto.getSortOrder()));
    entity.setGroupCode(String.valueOf(dto.getGroupCode()));
    entity.setDeductPoints(dto.getDeductPoints());
    entity.setRemark(dto.getRemark());
    entity.setExecutionCount(dto.getExecutionCount());
    entity.setRuleCode(dto.getRuleCode());
    return entity;
  }

  /**
  * 将传输对象转换为实体对象
  *
  * @param dto 传输对象
  * @param entity 原实体对象
  * @return 实体对象
  */
  public static DispatchConfigurat dto2entity(DispatchConfiguratReqDTO dto, DispatchConfigurat entity){
    if (dto == null) {
      return null;
    }
    if(Objects.nonNull(dto.getSortOrder())) {
      entity.setSortOrder(Integer.valueOf(dto.getSortOrder()));
    }
    if(Objects.nonNull(dto.getGroupCode())) {
      entity.setGroupCode(dto.getGroupCode());
    }
    if(Objects.nonNull(dto.getDeductPoints())) {
      entity.setDeductPoints(dto.getDeductPoints());
    }
    if(Objects.nonNull(dto.getRemark())) {
      entity.setRemark(dto.getRemark());
    }
    if(Objects.nonNull(dto.getExecutionCount())) {
      entity.setExecutionCount(dto.getExecutionCount());
    }
    if(Objects.nonNull(dto.getRuleCode())) {
      entity.setRuleCode(dto.getRuleCode());
    }
    return entity;
  }

  /**
  * 将实体对象转换为传输对象
  *
  * @param entity 实体对象
  * @return 传输对象
  */
  public static DispatchConfiguratRespVO entity2dto(DispatchConfigurat entity) {
    if (entity == null) {
      return null;
    }
    DispatchConfiguratRespVO dto = new DispatchConfiguratRespVO();
    dto.setId(entity.getId());
    dto.setSortOrder(entity.getSortOrder());
    dto.setGroupCode(entity.getGroupCode());
    dto.setDeductPoints(entity.getDeductPoints());
    dto.setRemark(entity.getRemark());
    dto.setExecutionCount(entity.getExecutionCount());
    dto.setRuleCode(entity.getRuleCode());
    dto.setCreateUser(entity.getCreateUser());
    dto.setCreateTime(entity.getCreateTime());
    dto.setModifyUser(entity.getModifyUser());
    dto.setModifyTime(entity.getModifyTime());
    return dto;
  }

}
